package com.mzj.saas.jobs.lock.service.haixiaoke;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.OSSObject;
import com.mzj.saas.commons.StatusCode;
import com.mzj.saas.jobs.backlog.entity.SmartLock;
import com.mzj.saas.jobs.bill.entity.SmartLockCard;
import com.mzj.saas.jobs.bill.entity.SmartLockFace;
import com.mzj.saas.jobs.bill.entity.SmartLockPwd;
import com.mzj.saas.jobs.commons.ResultBean;
import com.mzj.saas.jobs.lock.vo.yaluete.SmartLockVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @Author Dell
 * @Date 2023/9/8
 **/
@Slf4j
@Service
public class SmartLockHxkService {

    @Value("${haiXiaoKe.url}")
    private String haiXiaoKeUrl;
    @Value(("${haiXiaoKe.appId}"))
    private String haiXiaoKeAppid;
    @Value("${haiXiaoKe.appSecret}")
    private String haiXiaoKeAppSecret;

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private OSSClient ossClient;

    public SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

    public String haiXiaoKeParseDate(Date date) {
        if (date == null) {
            date = new Date();
        }
        return simpleDateFormat.format(date);
    }

    /**
     * 获取嗨小克平台token
     *
     * @return token
     */
    public String getToken() {
        String token = (String) redisTemplate.opsForValue().get("sys_haiXiaoKeToken");
        if (StringUtils.isEmpty(token)) {
            try {
                Map<String, Object> paramsMap = new HashMap<>(4);
                String nowTime = this.haiXiaoKeParseDate(null);
                paramsMap.put("appId", haiXiaoKeAppid);
                paramsMap.put("appSecret", haiXiaoKeAppSecret);
                paramsMap.put("sendTime", nowTime);
                paramsMap.put("randNonce", "123456");
                log.info("嗨小克--鉴权接口请求参数：{}",paramsMap);
                HttpResponse response = HttpRequest.post(haiXiaoKeUrl + "/login").body(JSONObject.toJSONString(paramsMap)).timeout(20000).execute();
                log.info("嗨小克--鉴权接口响应参数：{}",response.body());
                if (HttpStatus.HTTP_OK == response.getStatus()) {
                    JSONObject jsonObject = JSONObject.parseObject(response.body());
                    String code = jsonObject.getString("code");
                    if ( "0".equals(code)) {
                        JSONObject result = jsonObject.getJSONObject("result");
                        token = "Bearer " + result.getString("accessToken");
                        Integer expiresIn = result.getInteger("expiresIn");
                        redisTemplate.opsForValue().set("sys_haiXiaoKeToken",  token, expiresIn / 10, TimeUnit.MILLISECONDS);
                    } else {
                        log.error("嗨小克--鉴权请求响应数据异常：{}", jsonObject);
                    }
                } else {
                    log.error("嗨小克--鉴权请求失败，code：{}；body:{}", response.getStatus(), response.body());
                }
            } catch (Exception e) {
                log.error("嗨小克--鉴权请求异常：{}", e.getMessage(), e);
            }
        }
        String substring = token.substring(0, 1);
        if (substring.equals("\"")) {
//            token = token.substring(0, token.length() - 1);
            String[] split = token.split("\"");
            token = split[1];
        }
        return token;
    }

    public ResultBean<String> authorizationPwd(SmartLockVO vo, SmartLockPwd smartLockPwd) {
        String token = this.getToken();
        ResultBean<String> objectResultBean = new ResultBean<>();
        objectResultBean.setMsg("操作失败");
        objectResultBean.setCode(StatusCode.ERROR_CODE_10001.getErrorCode());
        if (StrUtil.isEmpty(token)) {
            log.error("嗨小克--授权智能锁用户密码接口--token为空");
            objectResultBean.setMsg("获取token失败");
            return objectResultBean;
        }
        try {
            Map<String, Object> paramsMap = new HashMap<>(4);
            String notTime = this.haiXiaoKeParseDate(null);
            paramsMap.put("sendTime", notTime);
            paramsMap.put("randNonce", "123456");
            paramsMap.put("deviceMac", vo.getSn());
            //角色，0普通用户,1管理员，2保洁
            paramsMap.put("userRole", "0");
            //用户id
            //身份证授权
            paramsMap.put("idNumber", vo.getPassword());
            paramsMap.put("password", vo.getPassword());
            paramsMap.put("startTime", this.haiXiaoKeParseDate(smartLockPwd.getStartTime()));
            paramsMap.put("endTime", this.haiXiaoKeParseDate(smartLockPwd.getEndTime() == null ? this.addTime(new Date()) : smartLockPwd.getEndTime()));
            log.info("嗨小克--添加用户接口密码授权请求参数：{}",paramsMap);
            HttpResponse response = HttpRequest.post(haiXiaoKeUrl + "/lock/addUser")
                    .header("Authorization", token).form(paramsMap).timeout(20000).execute();
            log.info("嗨小克--添加用户接口密码授权响应参数：{}",response.body());
            if (HttpStatus.HTTP_OK == response.getStatus()) {
                JSONObject jsonObject = JSONObject.parseObject(response.body());
                String code = jsonObject.getString("code");
                if ( "0".equals(code)) {
                    //维护数据库数据
                    objectResultBean.setMsg("操作成功");
                    objectResultBean.setCode(StatusCode.SUCCESS_CODE_10000.getErrorCode());
                    objectResultBean.setResultData(vo.getPassword());
                    return objectResultBean;
                } else {
                    log.error("嗨小克--授权门锁用户密码请求响应数据异常：{}", jsonObject);
                    objectResultBean.setMsg("添加失败：" + jsonObject.getString("message"));
                }
            } else {
                log.error("嗨小克--授权门锁用户密码请求失败，code：{}；body:{}", response.getStatus(), response.body());
                objectResultBean.setMsg("添加门卡信息响应错误");
            }
        } catch (Exception e) {
            objectResultBean.setMsg("添加门卡信息请求异常");
            log.error("嗨小克--授权门锁用户密码请求异常：{}", e.getMessage(), e);
        }
        return objectResultBean;
    }

    public ResultBean<String> deletePwd(SmartLockVO vo, Long lockAuthId) {
        String token = this.getToken();
        ResultBean<String> objectResultBean = new ResultBean<>();
        objectResultBean.setMsg("操作失败");
        objectResultBean.setCode(StatusCode.ERROR_CODE_10001.getErrorCode());
        if (StrUtil.isEmpty(token)) {
            objectResultBean.setMsg("获取token失败");
            log.error("嗨小克--删除智能锁用户密码接口--token为空");
            return objectResultBean;
        }
        try {
            Map<String, Object> paramsMap = new HashMap<>(4);
            String notTime = this.haiXiaoKeParseDate(null);
            paramsMap.put("sendTime", notTime);
            paramsMap.put("randNonce", "123456");
            paramsMap.put("deviceMac", vo.getSn());
            paramsMap.put("idNumber", vo.getIdentification());
            log.info("嗨小克--删除用户接口密码请求参数：{}",paramsMap);
            HttpResponse response = HttpRequest.post(haiXiaoKeUrl + "/lock/removeUser").header("Authorization", token).body(JSONObject.toJSONString(paramsMap)).timeout(20000).execute();
            log.info("嗨小克--删除用户接口密码响应参数：{}",response.body());
            if (HttpStatus.HTTP_OK == response.getStatus()) {
                JSONObject jsonObject = JSONObject.parseObject(response.body());
                String code = jsonObject.getString("code");
                if ( "0".equals(code)) {
                    objectResultBean.setMsg("操作成功");
                    objectResultBean.setCode(StatusCode.SUCCESS_CODE_10000.getErrorCode());
                    objectResultBean.setResultData(vo.getIdentification());
                    return objectResultBean;
                } else {
                    objectResultBean.setMsg("删除身份信息失败");
                    log.error("嗨小克--删除门锁用户密码请求响应数据异常：{}", jsonObject);
                }
            } else {
                objectResultBean.setMsg("删除密码信息响应失败");
                log.error("嗨小克--删除门锁用户密码请求失败，code：{}；body:{}", response.getStatus(), response.body());
            }
        } catch (Exception e) {
            objectResultBean.setMsg("删除身份信息请求异常");
            log.error("嗨小克--删除门锁用户密码请求异常：{}", e.getMessage(), e);
        }
        return objectResultBean;
    }

    public ResultBean<String> identityCardUnlocking(SmartLockVO vo, SmartLockCard smartLockCard) {
        String token = this.getToken();
        ResultBean<String> objectResultBean = new ResultBean<>();
        objectResultBean.setMsg("操作失败");
        objectResultBean.setCode(StatusCode.ERROR_CODE_10001.getErrorCode());
        if (StrUtil.isEmpty(token)) {
            log.error("嗨小克--授权智能锁用户密码接口--token为空");
            objectResultBean.setMsg("获取token失败");
            return objectResultBean;
        }
        try {
            Map<String, Object> paramsMap = new HashMap<>(4);
            String notTime = this.haiXiaoKeParseDate(null);
            paramsMap.put("sendTime", notTime);
            paramsMap.put("randNonce", "123456");
            paramsMap.put("deviceMac", vo.getSn());
            //用户id
//            paramsMap.put("userIndex", smartLock.getIdentification());
//            paramsMap.put("mobile", smartLock.getMobile());
//            paramsMap.put("userName", smartLock.getUserName());
            //身份证授权
            //角色，0普通用户,1管理员，2保洁
            paramsMap.put("userRole", "0");
            paramsMap.put("idNumber", smartLockCard.getCardNumber());
            paramsMap.put("cardNo", smartLockCard.getCardNumber());
            paramsMap.put("startTime", this.haiXiaoKeParseDate(smartLockCard.getStartTime()));
            paramsMap.put("endTime", this.haiXiaoKeParseDate(smartLockCard.getEndTime() == null ? this.addTime(new Date()) : smartLockCard.getEndTime()));
            log.info("嗨小克--门卡授权请求：{}",paramsMap);
            HttpResponse response = HttpRequest.post(haiXiaoKeUrl + "/lock/addUser")
                    .header("Authorization", token).form(paramsMap).timeout(20000).execute();
            log.info("嗨小克--门卡授权响应：{}",response.body());
            if (HttpStatus.HTTP_OK == response.getStatus()) {
                JSONObject jsonObject = JSONObject.parseObject(response.body());
                String code = jsonObject.getString("code");
                if ( "0".equals(code)) {
                    //维护数据库数据
                    objectResultBean.setMsg("操作成功");
                    objectResultBean.setCode(StatusCode.SUCCESS_CODE_10000.getErrorCode());
                    objectResultBean.setResultData(smartLockCard.getCardNumber());
                    return objectResultBean;
                } else {
                    log.error("嗨小克--授权门锁用户门卡请求响应数据异常：{}", jsonObject);
                    objectResultBean.setMsg("添加失败：" + jsonObject.getString("message"));
                }
            } else {
                log.error("嗨小克--授权门锁用户门卡请求失败，code：{}；body:{}", response.getStatus(), response.body());
                objectResultBean.setMsg("添加门卡信息响应错误");
            }
        } catch (Exception e) {
            objectResultBean.setMsg("添加门卡信息请求异常");
            log.error("嗨小克--授权门锁用户门卡请求异常：{}", e.getMessage(), e);
        }
        return objectResultBean;
    }

    public ResultBean<String> deleteIdentityCardUnlocking(SmartLockVO vo) {
        String token = this.getToken();
        ResultBean<String> objectResultBean = new ResultBean<>();
        objectResultBean.setMsg("操作失败");
        objectResultBean.setCode(StatusCode.ERROR_CODE_10001.getErrorCode());
        if (StrUtil.isEmpty(token)) {
            objectResultBean.setMsg("获取token失败");
            log.error("嗨小克--删除智能锁用户门卡接口--token为空");
            return objectResultBean;
        }
        try {
            Map<String, Object> paramsMap = new HashMap<>(4);
            String notTime = this.haiXiaoKeParseDate(null);
            paramsMap.put("sendTime", notTime);
            paramsMap.put("randNonce", "123456");
            paramsMap.put("deviceMac", vo.getSn());
            paramsMap.put("idNumber", vo.getIdentification());
            log.info("嗨小克--门卡删除请求：{}",paramsMap);
            HttpResponse response = HttpRequest.post(haiXiaoKeUrl + "/lock/removeUser").header("Authorization", token).body(JSONObject.toJSONString(paramsMap)).timeout(20000).execute();
            log.info("嗨小克--门卡删除响应：{}",response.body());
            if (HttpStatus.HTTP_OK == response.getStatus()) {
                JSONObject jsonObject = JSONObject.parseObject(response.body());
                String code = jsonObject.getString("code");
                if ( "0".equals(code)) {
                    objectResultBean.setMsg("操作成功");
                    objectResultBean.setCode(StatusCode.SUCCESS_CODE_10000.getErrorCode());
                    objectResultBean.setResultData(vo.getIdentification());
                    return objectResultBean;
                } else {
                    objectResultBean.setMsg("删除信息失败");
                    log.error("嗨小克--删除门锁用户门卡请求响应数据异常：{}", jsonObject);
                }
            } else {
                objectResultBean.setMsg("删除信息响应失败");
                log.error("嗨小克--删除门锁用户门卡请求失败，code：{}；body:{}", response.getStatus(), response.body());
            }
        } catch (Exception e) {
            objectResultBean.setMsg("删除身份信息请求异常");
            log.error("嗨小克--删除门锁用户门卡请求异常：{}", e.getMessage(), e);
        }
        return objectResultBean;
    }

    public ResultBean<String> deleteAll(String mac, Long lockId) {
        ResultBean<String> objectResultBean = new ResultBean<>();
        objectResultBean.setMsg("操作失败");
        objectResultBean.setCode(StatusCode.ERROR_CODE_10001.getErrorCode());
        String token = this.getToken();
        if (StrUtil.isEmpty(token)) {
            log.error("嗨小克--删除智能锁全部用户接口--token为空");
            objectResultBean.setMsg("获取token失败");
            return objectResultBean;
        }
        try {
            Map<String, Object> paramsMap = new HashMap<>(4);
            String notTime = this.haiXiaoKeParseDate(null);
            paramsMap.put("sendTime", notTime);
            paramsMap.put("randNonce", "123456");
            paramsMap.put("deviceMac", mac);
            paramsMap.put("removeAllUser", false);
            log.info("嗨小克--删除所有用户请求：{}",paramsMap);
            HttpResponse response = HttpRequest.post(haiXiaoKeUrl + "/lock/removeAllUser").header("Authorization", token).body(JSONObject.toJSONString(paramsMap)).timeout(20000).execute();
            log.info("嗨小克--删除所有用户响应：{}",response.body());
            if (HttpStatus.HTTP_OK == response.getStatus()) {
                JSONObject jsonObject = JSONObject.parseObject(response.body());
                String code = jsonObject.getString("code");
                if ( "0".equals(code)) {
                    objectResultBean.setCode(StatusCode.SUCCESS_CODE_10000.getErrorCode());
                    objectResultBean.setMsg("操作成功");
                    return objectResultBean;
                } else {
                    log.error("嗨小克--删除门锁全部用户请求响应数据异常：{}", jsonObject);
                    objectResultBean.setMsg("删除授权信息失败：" + jsonObject.getString("msg"));
                }
            } else {
                log.error("嗨小克--删除门锁全部用户请求失败，code：{}；body:{}", response.getStatus(), response.body());
                objectResultBean.setMsg("删除授权信息请求失败！");
            }
        } catch (Exception e) {
            log.error("嗨小克--删除门锁全部用户请求异常：{}", e.getMessage(), e);
            objectResultBean.setMsg("删除授权信息请求调用异常！");
        }
        return objectResultBean;
    }

    /**
     * 新增授权人脸信息
     *
     * @param smartLockFace 人脸信息
     * @return
     */
    public ResultBean<String> addFaceImage(SmartLockFace smartLockFace) {
        String token = this.getToken();
        ResultBean<String> objectResultBean = new ResultBean<>();
        objectResultBean.setMsg("操作失败");
        objectResultBean.setCode(StatusCode.ERROR_CODE_10001.getErrorCode());
        if (StrUtil.isEmpty(token)) {
            log.error("嗨小克--授权智能锁用户人脸接口--token为空");
            objectResultBean.setMsg("获取token失败");
            return objectResultBean;
        }
        String faceImage = smartLockFace.getFaceImage();
        try {
            Map<String, Object> paramsMap = new HashMap<>();
            String notTime = this.haiXiaoKeParseDate(null);
            //角色，0普通用户,1管理员，2保洁
            paramsMap.put("userRole", "0");
            paramsMap.put("sendTime", notTime);
            paramsMap.put("randNonce", "123456");
            paramsMap.put("deviceMac", smartLockFace.getSn());
            //身份证授权
            paramsMap.put("startTime", this.haiXiaoKeParseDate(smartLockFace.getStartTime()));
            paramsMap.put("endTime", this.haiXiaoKeParseDate(smartLockFace.getEndTime() == null ? this.addTime(new Date()) : smartLockFace.getEndTime()));
            //

            faceImage = faceImage.split("https://xj-saas-images.oss-cn-qingdao.aliyuncs.com/")[1];
            OSSObject object = ossClient.getObject("xj-saas-images", faceImage);
//            File file = new File("D:\\Java_study\\FilePathTest\\java.jpg");
            File file = File.createTempFile("stream2file", ".jpg");

            try (FileOutputStream out = new FileOutputStream(file)) {
                IOUtils.copy(object.getObjectContent(), out);
            }
            String l = "";
            if (StrUtil.isEmpty(smartLockFace.getIdentification())) {
                l = "" + System.currentTimeMillis() + RandomUtils.nextInt(100, 1000);
            } else {
                l = smartLockFace.getIdentification();
            }
//            paramsMap.put("file", file);
            paramsMap.put("idNumber",l);
            log.info("嗨小克--添加用户人脸授权请求：{}，人脸照：{}",paramsMap,smartLockFace.getFaceImage());
            HttpResponse response = HttpRequest.post(haiXiaoKeUrl + "/lock/addUser")
                    .header("Authorization", token).form("file",file)
                    .form(paramsMap).timeout(20000).execute();
            log.info("嗨小克--添加用户人脸授权响应：{}",response.body());
            object.close();
            if (HttpStatus.HTTP_OK == response.getStatus()) {
                JSONObject jsonObject = JSONObject.parseObject(response.body());
                String code = jsonObject.getString("code");
                if ("0".equals(code)) {
                    objectResultBean.setMsg("操作成功");
                    objectResultBean.setCode(StatusCode.SUCCESS_CODE_10000.getErrorCode());
                    objectResultBean.setResultData(l);
                    return objectResultBean;
                } else {
                    log.error("嗨小克--授权门锁用户人脸请求响应数据异常：{}", jsonObject);
                    objectResultBean.setMsg("添加失败：" + jsonObject.getString("message"));
                }
            } else {
                log.error("嗨小克--授权门锁用户人脸请求失败，code：{}；body:{}", response.getStatus(), response.body());
                objectResultBean.setMsg("添加人脸信息响应错误");
            }
        } catch (Exception e) {
            objectResultBean.setMsg("添加人脸信息请求异常");
            log.error("嗨小克--授权门锁用户人脸请求异常：{}", e.getMessage(), e);
        }
        return objectResultBean;
    }


    public ResultBean<String> updateFaceImage(SmartLockFace smartLockFace) {
        String token = this.getToken();
        ResultBean<String> objectResultBean = new ResultBean<>();
        objectResultBean.setMsg("操作失败");
        objectResultBean.setCode(StatusCode.ERROR_CODE_10001.getErrorCode());
        if (StrUtil.isEmpty(token)) {
            log.error("嗨小克--授权智能锁用户人脸接口--token为空");
            objectResultBean.setMsg("获取token失败");
            return objectResultBean;
        }
        String faceImage = smartLockFace.getFaceImage();
        try {
            Map<String, Object> paramsMap = new HashMap<>();
            String notTime = this.haiXiaoKeParseDate(null);
            paramsMap.put("sendTime", notTime);
            paramsMap.put("randNonce", "123456");
            paramsMap.put("deviceMac", smartLockFace.getSn());
            //角色，0普通用户,1管理员，2保洁
            paramsMap.put("userRole", "0");
            //身份证授权
            paramsMap.put("startTime", this.haiXiaoKeParseDate(smartLockFace.getStartTime()));
            paramsMap.put("endTime", this.haiXiaoKeParseDate(smartLockFace.getEndTime() == null ? this.addTime(new Date()) : smartLockFace.getEndTime()));
            //

            faceImage = faceImage.split("https://xj-saas-images.oss-cn-qingdao.aliyuncs.com/")[1];
            OSSObject object = ossClient.getObject("xj-saas-images", faceImage);
//            File file = new File("D:\\Java_study\\FilePathTest\\java.jpg");
            File file = File.createTempFile("stream2file", ".jpg");

            try (FileOutputStream out = new FileOutputStream(file)) {
                IOUtils.copy(object.getObjectContent(), out);
            }
//            paramsMap.put("file", file);
            paramsMap.put("idNumber",smartLockFace.getIdentification());
            log.info("嗨小克--人脸授权修改请求：{}，人脸照：{}",paramsMap,smartLockFace.getFaceImage());
            HttpResponse response = HttpRequest.post(haiXiaoKeUrl + "/lock/addUser")
                    .header("Authorization", token).form("file",file)
                    .form(paramsMap).timeout(20000).execute();
            log.info("嗨小克--人脸授权修改响应：{}",response.body());
            object.close();
            if (HttpStatus.HTTP_OK == response.getStatus()) {
                JSONObject jsonObject = JSONObject.parseObject(response.body());
                String code = jsonObject.getString("code");
                if ("0".equals(code)) {
                    objectResultBean.setMsg("操作成功");
                    objectResultBean.setCode(StatusCode.SUCCESS_CODE_10000.getErrorCode());
                    return objectResultBean;
                } else {
                    log.error("嗨小克--授权门锁用户人脸请求响应数据异常：{}", jsonObject);
                    objectResultBean.setMsg("添加失败：" + jsonObject.getString("message"));
                }
            } else {
                log.error("嗨小克--授权门锁用户人脸请求失败，code：{}；body:{}", response.getStatus(), response.body());
                objectResultBean.setMsg("添加人脸信息响应错误");
            }
        } catch (Exception e) {
            objectResultBean.setMsg("添加人脸信息请求异常");
            log.error("嗨小克--授权门锁用户人脸请求异常：{}", e.getMessage(), e);
        }
        return objectResultBean;
    }

    public Date addTime(Date nowTime){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(nowTime);
        calendar.add(Calendar.YEAR, 100);
        return calendar.getTime();
    }


    /**
     * 删除授权人脸信息
     *
     * @param smartLockFace 授权人脸信息
     * @return
     */
    public ResultBean<String> deleteFaceImage(SmartLockFace smartLockFace) {
        String token = this.getToken();
        String substring = token.substring(1, token.length() - 1);
        ResultBean<String> objectResultBean = new ResultBean<>();
        objectResultBean.setMsg("操作失败");
        objectResultBean.setCode(StatusCode.ERROR_CODE_10001.getErrorCode());
        if (StrUtil.isEmpty(token)) {
            objectResultBean.setMsg("获取token失败");
            log.error("嗨小克--删除智能锁用户人脸接口--token为空");
            return objectResultBean;
        }
        try {
            Map<String, Object> paramsMap = new HashMap<>(4);
            String notTime = this.haiXiaoKeParseDate(null);
            paramsMap.put("sendTime", notTime);
            paramsMap.put("randNonce", "123456");
            paramsMap.put("deviceMac", smartLockFace.getSn());
            paramsMap.put("idNumber", smartLockFace.getIdentification());
            log.info("嗨小克--删除人脸授权请求：{}",paramsMap);
            HttpResponse response = HttpRequest.post(haiXiaoKeUrl + "/lock/removeUser").header("Authorization", token).body(JSONObject.toJSONString(paramsMap)).timeout(20000).execute();
            log.info("嗨小克--删除人脸授权响应：{}",response.body());
            if (HttpStatus.HTTP_OK == response.getStatus()) {
                JSONObject jsonObject = JSONObject.parseObject(response.body());
                String code = jsonObject.getString("code");
                if ("0".equals(code)) {
                    objectResultBean.setMsg("操作成功");
                    objectResultBean.setCode(StatusCode.SUCCESS_CODE_10000.getErrorCode());
                    objectResultBean.setResultData(smartLockFace.getIdentification());
                    return objectResultBean;
                } else {
                    objectResultBean.setMsg("删除信息失败");
                    log.error("嗨小克--删除门锁用户人脸请求响应数据异常：{}", jsonObject);
                }
            } else {
                objectResultBean.setMsg("删除信息响应失败");
                log.error("嗨小克--删除门锁用户人脸请求失败，code：{}；body:{}", response.getStatus(), response.body());
            }
        } catch (Exception e) {
            objectResultBean.setMsg("删除身份信息请求异常");
            log.error("嗨小克--删除门锁用户人脸请求异常：{}", e.getMessage(), e);
        }
        return objectResultBean;
    }

    public ResultBean<String> selectLockList(SmartLock smartLock) {
        ResultBean<String> objectResultBean = new ResultBean<>();
        objectResultBean.setMsg("操作失败");
        objectResultBean.setCode(StatusCode.ERROR_CODE_10001.getErrorCode());
        String token = this.getToken();
        if (StrUtil.isEmpty(token)) {
            log.error("嗨小克--获取智能锁信息接口--token为空");
            return objectResultBean;
        }
        try {
            Map<String, Object> paramsMap = new HashMap<>(4);
            paramsMap.put("page", 1);
            paramsMap.put("pageSize", 1);
            paramsMap.put("randNonce", "123456");
            if (StrUtil.isNotEmpty(smartLock.getSn())) {
                paramsMap.put("deviceMac", smartLock.getSn());
            }
            String nowTime = this.haiXiaoKeParseDate(null);
            paramsMap.put("sendTime", nowTime);
            //表示获取最后更新时间后状态有新变化设备，用于减少每次同步的数量
            //paramsMap.put("lastSyncTime", nowTime);
            log.info("嗨小克--查询锁列表请求：{}",paramsMap);
            HttpResponse response = HttpRequest.post(haiXiaoKeUrl + "/getDeviceList").header("Authorization", token).body(JSONObject.toJSONString(paramsMap)).timeout(20000).execute();
            log.info("嗨小克--查询锁列表响应：{}",response.body());
            if (HttpStatus.HTTP_OK == response.getStatus()) {
                JSONObject jsonObject = JSONObject.parseObject(response.body());
                String code = jsonObject.getString("code");
                if ( "0".equals(code)) {
                    objectResultBean.setMsg("操作成功");
                    objectResultBean.setCode(StatusCode.SUCCESS_CODE_10000.getErrorCode());
                    objectResultBean.setResultData(response.body());
                    return objectResultBean;
                } else {
                    log.error("嗨小克--查询门锁列表请求响应数据异常：{}", jsonObject);
                }
            } else {
                log.error("嗨小克--查询门锁列表请求失败，code：{}；body:{}", response.getStatus(), response.body());
            }
        } catch (Exception e) {
            log.error("嗨小克--查询门锁列表请求异常：{}", e.getMessage(), e);
        }
        return objectResultBean;
    }

/*    public String getSmartLock(SmartLock smartLock) {
        if (StrUtil.isEmpty(smartLock.getSn())) {
            log.error("智能锁的sn信息为空");
            return null;
        }
        String token = this.getToken();
        if (StrUtil.isEmpty(token)) {
            log.error("嗨小克--获取智能锁信息接口--token为空");
            return null;
        }
        try {
            Map<String, Object> paramsMap = new HashMap<>(4);
            paramsMap.put("page", 1);
            paramsMap.put("pageSize", 1);
            paramsMap.put("deviceMac", smartLock.getSn());
            paramsMap.put("randNonce", "123456");
            *//*String nowTime = this.haiXiaoKeParseDate();
            paramsMap.put("sendTime", nowTime);
            //表示获取最后更新时间后状态有新变化设备，用于减少每次同步的数量
            paramsMap.put("lastSyncTime", nowTime);*//*
            HttpResponse response = HttpRequest.post(haiXiaoKeUrl + "/getDeviceList").header("Authorization", token).body(JSONObject.toJSONString(paramsMap)).timeout(20000).execute();
            if (HttpStatus.HTTP_OK == response.getStatus()) {
                JSONObject jsonObject = JSONObject.parseObject(response.body());
                String code = jsonObject.getString("code");
                if ( "0".equals(code)) {
                    return jsonObject.getString("result");
                } else {
                    log.error("嗨小克--查询门锁列表请求响应数据异常：{}", jsonObject);
                }
            } else {
                log.error("嗨小克--查询门锁列表请求失败，code：{}；body:{}", response.getStatus(), response.body());
            }
        } catch (Exception e) {
            log.error("嗨小克--查询门锁列表请求异常：{}", e.getMessage(), e);
        }
        return null;
    }*/
}
